
tasks = [5, 4, 1]

# enumerate: 列举
for i, t in enumerate(tasks):
  print(i, ":", t)

def minimumWaitingTime(tasks):
  tasks.sort()
  totalWaitingTime = 0

  for i, t in enumerate(tasks):
    tasksLeft = len(tasks) - i - 1
    totalWaitingTime += (tasksLeft * t)
  
  return totalWaitingTime